package com.sbj.controller;

import com.sbj.dto.req.CarReq;
import com.sbj.dto.res.CarRes;
import com.sbj.service.CarService;
import com.zmh.framework.util.Result;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author summer
 * @version 1.0
 * @date 2024/9/10 09:56
 */
@RestController
@RequestMapping(value = "/member_car")
@AllArgsConstructor
public class MemberCarController {

    private final CarService carService;

    /**
     * 购物车数量
     * @return
     */
    @GetMapping(value = "/car_num")
    public Result<Long> carNum(){
        Long count=carService.carNum();
        return Result.successResult(count);
    }

    /**
     * 会员购物车列表
     * @return
     */
    @GetMapping(value = "/lists")
    public Result<List<CarRes>> lists(){

        return Result.successResult(carService.lists());
    }

    /**
     * 添加购物车
     * @param carReq
     * @return
     */
    @PostMapping(value = "/add_car")
    public Result<String> addCar(@RequestBody CarReq carReq){
        carService.saveCar(carReq);
        return Result.successResult();
    }

    /**
     *  更新购物车商品的选中状态
     * @param carReqs
     * @return
     */
    @PostMapping(value = "update_car_checked")
    public Result<String> carChecked(@RequestBody List<CarReq> carReqs){
        carService.carChecked(carReqs);
        return Result.successResult();
    }

    /**
     * 删除购物车
     * @param id
     * @return
     */
    @GetMapping(value = "/remove_car/{id}")
    public Result<String> removeCar(@PathVariable Integer id){
        carService.removeById(id);
        return Result.successResult();
    }
}
